<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../include/taglib.jsp" %>
<div id="tableList" class="tableList">
    <script>
        YUI().use('sortable', function (Y) {
            var sortable = new Y.Sortable({
                container: '#tableList',
                nodes: 'li',
                opacity: '.1'
            });
        });
    </script>
    <div id="title">
        <table class="table table-striped table-advance table-hover table-condensed">
            <thead>
            <tr>
                <th width="5%">#</th>
                <th width="15%">名称</th>
                <th width="10%">接口标识</th>
                <th width="10%">数据源</th>
                <th width="10%">状态</th>
                <th width="15%">生效产品</th>
                <th width="10%">启用平台</th>
                <th width="10%">类型</th>
                <th width="10%">排行榜展示数</th>
                <th width="10%">包含内容数</th>
                <th width="10%">封面图</th>
                <th width="10%">操作</th>
            </tr>
            </thead>
        </table>
    </div>
    <div>
        <c:forEach items="${pages.result}" var="rank" varStatus="status">
            <li style="width: 100%;">
                <table class="table table-striped table-advance table-hover table-condensed"
                       style="margin-bottom: 0px;">
                    <tbody>
                    <tr>
                        <td width="5%"><input type="hidden" name="sortIds"
                                              value="${rank.id}"/><font color="blue">${status.index+1}</font></td>
                        <td width="15%"><a
                                href="javascript:jumpMenu('${ctx }/recommenddetail/rank/page?colRankId=${rank.id}&enabledPro=${enabledPro}')"><strong>${rank.colName}</strong></a>
                        </td>
                        <td width="10%"><input type="text" readonly value="${rank.colRankNum}" size="8"/></td>
                        <td width="10%">
                            <c:if test="${rank.robotFlag == 0}">CMS配置</c:if>
                            <c:if test="${rank.robotFlag == 1}">自动化数据</c:if>
                        </td>
                        <td width="10%">
                            <div class="btn-group">
                                <c:if test='${rank.colState  == -1 }'>
                                    <a class="btn btn-danger btn-xs" href="#">停用</a>
                                    <a class="btn btn-danger btn-xs dropdown-toggle" data-toggle="dropdown" href="#">
                                        <span class="fa fa-caret-down"></span></a>
                                </c:if>
                                <c:if test='${rank.colState  == 1 }'>
                                    <a class="btn btn-success btn-xs" href="#">启用</a>
                                    <a class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" href="#">
                                        <span class="fa fa-caret-down"></span></a>
                                </c:if>
                                <c:if test='${rank.colState  == 3 }'>
                                    <a class="btn btn-warning btn-xs" href="#">审核</a>
                                    <a class="btn btn-warning btn-xs dropdown-toggle" data-toggle="dropdown" href="#">
                                        <span class="fa fa-caret-down"></span></a>
                                </c:if>
                                <ul class="dropdown-menu">
                                    <li style="width: auto" onclick="changeStatus(this);">
                                        <a class="btn btn-success btn-xs">
                                            启用
                                            <input type="hidden" name="id"
                                                   value="${rank.id}"/>
                                            <input type="hidden" name="colState" value="1"/>
                                        </a>
                                    </li>
                                    <li style="width: auto" onclick="changeStatus(this);">
                                        <a class="btn btn-danger btn-xs">
                                            停用
                                            <input type="hidden" name="id"
                                                   value="${rank.id}"/>
                                            <input type="hidden" name="colState" value="-1"/>
                                        </a>
                                    </li>
                                    <c:if test='${rank.robotFlag  == 0 }'>
                                        <li style="width: auto" onclick="changeStatus(this);">
                                            <a class="btn btn-warning btn-xs">
                                                审核
                                                <input type="hidden" name="id"
                                                       value="${rank.id}"/>
                                                <input type="hidden" name="colState" value="3"/>
                                            </a>
                                        </li>
                                    </c:if>
                                </ul>
                            </div>
                        </td>
                        <td width="15%">
                            <c:forEach items="${products}" var="product">
                                <c:if test="${fn:indexOf(rank.enabledPro, product.proNum)>-1}">${product.icon}</c:if>
                            </c:forEach>
                        </td>
                        <td width="10%">${rank.platForm}</td>
                        <td width="10%">
                            <c:if test='${rank.colVideoType  == 1 }'>电视剧</c:if>
                            <c:if test='${rank.colVideoType  == 2 }'>电影</c:if>
                            <c:if test='${rank.colVideoType  == 3 }'>动漫</c:if>
                            <c:if test='${rank.colVideoType  == 4 }'>综艺</c:if>
                            <c:if test='${rank.colVideoType  == 16 }'>纪录片</c:if>
                            <c:if test='${rank.colVideoType  == 6 }'>儿童</c:if>
                        </td>
                        <td width="10%">
                                ${rank.outsideNum}
                        </td>
                        <td width="10%">
                                ${rank.insideNum}
                        </td>
                        <td width="10%">
                            <c:if test="${empty rank.colPoster}"><font
                                    color="red">空</font></c:if>
                            <c:if test="${not empty rank.colPoster}">
                                <a href="${rank.colPoster}"
                                   target="_blank"><img
                                        src="${rank.colPoster}" height="32"
                                        width="24"/></a>
                            </c:if>
                        </td>
                        <td width="10%">
                            <button title="删除" class="btn btn-danger btn-xs" onclick="del(${rank.id});"><i
                                    class="fa fa-trash-o fa-2x"></i>
                            </button>
                            &nbsp;
                            <button onclick="edit(${rank.id});" title="编辑" class="btn btn-primary btn-xs"
                                    data-toggle="modal"
                                    data-target="#myModal"><i class="fa fa-pencil fa-2x"></i>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </li>
        </c:forEach>
    </div>
</div>
<div class="col-md-12">
    <%@include file="../include/page.jsp" %>
</div>
<script type="text/javascript">
    function changeStatus(obj) {
        var id = $(obj).find("input[name=id]").val();
        var colState = $(obj).find("input[name=colState]").val();
        var package = new AJAXPacket("${ctx}/rank/chgState")
        package.data.add("id", id);
        package.data.add("colState", colState);
        core.ajax.sendPacket(package, function (response) {
            if (response.data.success) {
                alertMsg.correct("成功！");
                jumpPageTo('_list');
            } else {
                alertMsg.error(response.data.errMsg);
            }
        });
        package = null;
    }
</script>